package com.itstu.gulimall.seckill.controller;

import com.itstu.common.utils.R;
import com.itstu.gulimall.seckill.service.SeckillService;
import com.itstu.gulimall.seckill.to.SecKillSkuRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shhjiang_001
 * @create 2020-06-05 13:39
 */
@RestController
public class SeckillController {
    @Autowired
    SeckillService seckillService;

    /**
     * 获取当前参与秒杀的信息
     * @return
     */
    @GetMapping("/currentSeckillSku")
    public R getCurrentSeckillSkus(){
        List<SecKillSkuRedisTo> vos = seckillService.getCurrentSeckillSkus();
        return R.ok().setData(vos);
    }
    @GetMapping("/kill")
    public R kill(@RequestParam("killId") String killId,
                  @RequestParam("key") String key,
                  @RequestParam("num") Integer num){

        // 1. 拦截器确认是否登录
        String ordersn = seckillService.kill(killId,key,num);
        return R.ok().setData(ordersn);
    }

}
